Sub 考勤自动化()
Application.ScreenUpdating = False
Set dxx = CreateObject("scripting.dictionary") '//休息
Set dam1 = CreateObject("scripting.dictionary") '//上午上班
Set dam1g = CreateObject("scripting.dictionary") '//上午上班结果
Set dam2 = CreateObject("scripting.dictionary") '//上午下班
Set dam2g = CreateObject("scripting.dictionary") '//上午下班结果
Set dpm1 = CreateObject("scripting.dictionary") '//下午上班
Set dpm1g = CreateObject("scripting.dictionary") '//下午上班结果
Set dpm2 = CreateObject("scripting.dictionary") '//下午下班
Set dpm2g = CreateObject("scripting.dictionary") '//下午下班结果

bx1 = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
arr = Sheet1.Range("A5:P" & bx1)
For i = 1 To UBound(arr)
    ri = Mid(arr(i, 7), 7, 2) * 1
    na = arr(i, 1) & "," & ri
    dxx(na) = arr(i, 8)
    dam1(na) = arr(i, 9)
    dam1g(na) = arr(i, 10)
    dam2(na) = arr(i, 11)
    dam2g(na) = arr(i, 12)
    dpm1(na) = arr(i, 13)
    dpm1g(na) = arr(i, 14)
    dpm2(na) = arr(i, 15)
    dpm2g(na) = arr(i, 16)
    
    
Next

bx2 = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row - 5
For h = 4 To bx2 Step 5
    
    For lx = 4 To 34
    'Stop
        na = Cells(h, 2) & "," & Cells(3, lx)
        
        If dam1(na) <> "" Then '//======================上午上班
            Cells(h, lx) = "√"
        Else
            If dxx(na) = "休息" Then
                Cells(h, lx) = ""
            Else
                If dam1g(na) = "请假" Then
                    Cells(h, lx) = "T"
                Else
                    Cells(h, lx) = "缺"
                End If
                
            End If
        End If
        
        If dam2(na) <> "" Then '//======================上午上班
            Cells(h + 1, lx) = "√"
        Else
            If dxx(na) = "休息" Then
                Cells(h + 1, lx) = ""
            Else
                If dam2g(na) = "请假" Then
                    Cells(h + 1, lx) = "T"
                Else
                    Cells(h + 1, lx) = "缺"
                End If
                
            End If
        End If
        
        If dpm1(na) <> "" Then '//======================下午上班
            Cells(h + 2, lx) = "√"
        Else
            If dxx(na) = "休息" Then
                Cells(h + 2, lx) = ""
            Else
                If dpm1g(na) = "请假" Then
                    Cells(h + 2, lx) = "T"
                Else
                    Cells(h + 2, lx) = "缺"
                End If
                
            End If
        End If
        
         If dpm2(na) <> "" Then '//======================上午上班
            Cells(h + 3, lx) = "√"
        Else
            If dxx(na) = "休息" Then
                Cells(h + 3, lx) = ""
            Else
                If dpm2g(na) = "请假" Then
                    Cells(h + 3, lx) = "T"
                Else
                    Cells(h + 3, lx) = "缺"
                End If
                
            End If
        End If
    
    
    Next
'Stop
Next


Application.ScreenUpdating = True
MsgBox "完成，请手动检查班次为休息的打卡情况！"
End Sub